package com.keyancompany.zhongbaopingtai.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.utils.DensityUtils;
import com.keyancompany.zhongbaopingtai.utils.ScreenUtils;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.photoselector.model.PhotoModel;

import java.util.List;

/**
 * Created by firefox on 2016/6/20.
 */
public class ImageAdapter extends ListAdapter<PhotoModel> {

    private int ItemWidth;

    public ImageAdapter(Context ctx, List<PhotoModel> photos) {
        super(photos, ctx);
        ItemWidth = (ScreenUtils.getScreenWidth(ctx) - DensityUtils.dp2px(ctx, 10)) / 4;
    }

    @Override
    public int getContentViewId() {
        return R.layout.item_photo;
    }

    @Override
    public HolderView getHoldView(int position, View contentView, ViewGroup parent) {
        ImageHolder hold = new ImageHolder();
        hold.imageView = (ImageView) contentView.findViewById(R.id.image);
        hold.imageView.setLayoutParams(new ViewGroup.LayoutParams(ItemWidth, ItemWidth));
        return hold;
    }

    @Override
    public void setItemView(int position, HolderView contentView, PhotoModel item) {
        ImageHolder hold = (ImageHolder) contentView;
//        hold.imageView

        ImageLoader.getInstance().displayImage("file:///" + item.getOriginalPath(), hold.imageView);
    }

    public class ImageHolder extends HolderView {
        ImageView imageView;

    }
}
